package com.gtpickupapp;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.app.LocalActivityManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class MapOverlays extends ItemizedOverlay {

	private ArrayList<OverlayItem> myOverlays = new ArrayList<OverlayItem>();
	Context myContext;
	Bundle bundle;
	
	public MapOverlays(Drawable defaultMarker, Context context){
		//super(defaultMarker);
		super(boundCenterBottom(defaultMarker));
		myContext = context;
	}
	
	public MapOverlays(Drawable defaultMarker, Context context, Bundle b){
		//super(defaultMarker);
		super(boundCenterBottom(defaultMarker));
		myContext = context;
		bundle = b;
		
	}
	
	@Override
	protected boolean onTap(int index){
		OverlayItem item = myOverlays.get(index);
		
		//AlertDialog.Builder dialog = new AlertDialog.Builder(myContext);
		//dialog.setTitle(item.getTitle());
		//dialog.setMessage(item.getSnippet());
		//dialog.show();
		//TODO redirect Activity here
		
		//
		
        
        
		//Use Title for the location of the event
    	Intent myintent = new Intent(myContext, CreateNewEvent.class);
    	bundle.putString("location", item.getTitle());
    	myintent.putExtras(bundle);
    	NewEventGroup g = NewEventGroup.group;
    	LocalActivityManager la = g.getLocalActivityManager();
    	View view = la.startActivity("newevent",myintent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
    	NewEventGroup.group.replaceView(view);
		return true;
	}
	
	public MapOverlays(Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));
	}
	
	public void addOverlay(OverlayItem overlay){
		myOverlays.add(overlay);
		populate();
	}

	@Override
	protected OverlayItem createItem(int i) {
		// TODO Auto-generated method stub
		return myOverlays.get(i);
	}

	@Override
	public int size() {
		// TODO Auto-generated method stub
		return myOverlays.size();
	}

}
